package com.bawei.fuxi;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;

import com.bawei.fuxi.base.mvp.BaseActivity;
import com.bawei.fuxi.base.mvp.BasePresenter;
import com.bawei.fuxi.ui.friends.FriendsFragment;
import com.bawei.fuxi.ui.home.HomeFragment;
import com.bawei.fuxi.fragment.MeFragment;
import com.bawei.fuxi.fragment.MyFragmentPagerAdapter;
import com.bawei.fuxi.fragment.SheQuFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends BaseActivity {
    private ViewPager viewPager;
    private BottomNavigationView bottom;
    private List<Fragment> mList = new ArrayList<>();
    private MyFragmentPagerAdapter mMyFragmentPagerAdapter;




    @Override
    public int bindLayout() {
        return R.layout.activity_main;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void initView(Bundle savedInstanceState) {
        requestPermissions(new String[]{
                "android.permission.VIBRATE",
                "android.permission.RECORD_AUDIO" ,
                "android.permission.CAMERA",
                "android.permission.ACCESS_NETWORK_STATE",
                "android.permission.WRITE_EXTERNAL_STORAGE" ,
                "android.permission.ACCESS_FINE_LOCATION",
                "android.permission.GET_TASKS" ,
                "android.permission.ACCESS_WIFI_STATE" ,
                "android.permission.CHANGE_WIFI_STATE" ,
                "android.permission.WAKE_LOCK",
                "android.permission.MODIFY_AUDIO_SETTINGS",
                "android.permission.READ_PHONE_STATE",
                "android.permission.RECEIVE_BOOT_COMPLETED",
                "android.permission.FOREGROUND_SERVICE",
                "android.permission.ACCESS_COARSE_LOCATION"
        },101);
        viewPager = (ViewPager) findViewById(R.id.view_pager);
        bottom = (BottomNavigationView) findViewById(R.id.bottom);

        mList.add(new HomeFragment());
        mList.add(new FriendsFragment());
        mList.add(new SheQuFragment());
        mList.add(new MeFragment());
        mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,mList);
        viewPager.setAdapter(mMyFragmentPagerAdapter);
        //上下联动
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                bottom.getMenu().getItem(position).setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        bottom.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.home:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.friends:
                        viewPager.setCurrentItem(1);
                        break;
                    case R.id.shequ:
                        viewPager.setCurrentItem(2);
                        break;
                    case R.id.me:
                        viewPager.setCurrentItem(3);
                        break;
                }
                return true;
            }
        });
        //默认红点
        bottom.getOrCreateBadge(R.id.home).setNumber(23);


    }

    @Override
    public BasePresenter createPresenter() {
        return null;
    }

    @Override
    public void initData() {

    }
}